const app = getApp();
import md5 from '../../utils/md5.js';
import trigger from '../../utils/util.js'
Page({
	data: {
		stpe: '',
		g_iphone: '',
		class_on: '',
		class_on2: '',
		li_on: '请选择分类',
		sku_on: ['on'],
		resourceDomain: app.resourceDomain,
		selectBox: true,
		getPhoneBox: true,
		sku:0,
		mid_num:1,
		time_type:1,
		CartWrds:'加入购物车',
		CartClick:false,
		back:'back',
    isShow: false
	},
	phone_click() {
		wx.makePhoneCall({
			phoneNumber: '4001000908'
		})
	},
	CartGet:function(e){
		//加入购物车
		if(this.data.li_on == "请选择分类") {
			this.class_suo = true;
			this.setData({
				class_on: 'on',
				class_on2: 'on',
				CartClick:true
			})
		}else{
			var that=this;
			app.request(app.apiDomain + 'index.php?c=cart&a=addCart', {
				goods_id:that.goods_id,
				sku:that.data.sku_get,
				num:that.data.mid_num,
			}, function(res) {
				console.log(res.data.info)
				that.setData({
					CartWrds:'添加成功',
					back:'get'
				})
			});
		}
	},
	onLoad: function(options) {
    app.updateFlag(this)
    // console.log(options)
    this.options = options
    // this.setData({
    //   options: options
    // })
		this.li_wrds = false;
		this.sku_get = false;
		//id=goods_id uid=user_id  type 1健康币 2助力
		var scene = decodeURIComponent(options.scene);
		console.log(scene,'二维码获取的值')
		if (typeof scene !== 'undefined') {
			var scene_obj = app.scene_decode(scene);
			//
			if(scene_obj.id){
				options.goods_id = scene_obj.id;
			};
			if(scene_obj.uid){
				options.user_id = scene_obj.uid
			};
			if(scene_obj.type == 1){
				options.type = 'exchange'
			}else if(scene_obj.type == 2){
				options.type = 'assist'
			}else if(scene_obj.type == 3){
				options.type = 'time'
			};
		}
		// console.log(options,'打印options')
		
		var that = this;
		this.ren_suo = 1;
		this.canvas_num = 0;
		this.o_type = options.type;
		this.goods_id = options.goods_id;
		this.canvas_suo=false;
		wx.setStorageSync("goods_sku", 0);
		//获取购物车
		
		//授权
		// app.checkSession(this,'../mall/detail',options.goods_id,options.type);
		// 旧接口
		// app.request(app.apiDomain + 'index.php?c=mall&a=goodsdetail', {
		// 	goods_id: options.goods_id
		// }, function(res) {
		// 	if(res.data.status == '1') {
		// 		var submiturl = '../Order/submit';
		// 		var goods = res.data.data;
		// 		var sku_price_num = goods.sku_price_list[0].total_price+'';
		// 		that.this_time = Math.round(new Date() / 1000);
		// 		var min_pr = goods.f_sku_list[that.data.sku];
		// 		if(min_pr[5]){
		// 			var min_price = min_pr[5] 
		// 		}else if(goods.f_min_price){
		// 			var min_price = goods.f_min_price
		// 		}else{
		// 			var min_price = min_pr[1];
		// 		};
		// 		// console.log(goods.f_sku_list[that.data.sku][4],123);
		// 		that.setData({
		// 			goods: goods,
		// 			type: options.type,
		// 			goods_id: options.goods_id,
		// 			width: (100 / goods.f_need_assist_num) * goods.has_assist_num + '%',
		// 			user_id: wx.getStorageSync('user_id'),
		// 			isGifts: goods.f_is_gifts == 2 ? 'ok' : 'no',
		// 			url:'Help?goods_id='+options.goods_id+'&user_id='+wx.getStorageSync('user_id'),
		// 			sku_price_num:sku_price_num.split("."),
		// 			banner:goods.f_carousel_img_arr,
		// 			min_price:min_price,
		// 			this_time:that.this_time,
		// 			sheng_num:(goods.first_sku[3] - goods.first_sku[1]).toFixed(1)
		// 		});
				
		// 		//抢购倒计时
		// 		if(options.type == 'time' && goods.f_end_time > that.this_time){
		// 			that.time_num = 0;
		// 			that.dynamic_time = 1;
		// 			if(parseFloat(goods.f_begin_time) > that.this_time){ //即将开始
		// 				that.time_type = 1;
		// 			}else if(parseFloat(goods.f_begin_time) < that.this_time){//进行中
		// 				that.time_type = 2;
		// 				that.setData({
		// 					time_type:2,
		// 				})	
		// 			};
		// 			that.time_function(that,goods)//先执行一次 在循环
		// 			setInterval(function(){
		// 				that.time_function(that,goods)
		// 			},1000)
		// 		}else{//已经结束
		// 			that.time_type = 3;
		// 			that.setData({
		// 				time_type:3
		// 			})	
		// 		}
				
		// 		//
		// 		wx.setNavigationBarTitle({
		// 			title: res.data.data.f_name,
		// 		})
		// 		var WxParse = require('../../wxParse/wxParse.js');
		// 		wx.setStorageSync('title', res.data.data.f_name);
		// 		var article = res.data.data.f_detail_context;
		// 		WxParse.wxParse('article', 'html', article, that, 0);
				
				
		// 		//请求商品图片
		// 		wx.downloadFile({
		// 			url: 'https://resource.160nurse.com/' + goods.f_carousel_img_arr[0], //
		// 			success(res) {
		// 				if (res.statusCode === 200) {
		// 					that.canvas_mall = res.tempFilePath;
		// 					that.canvas_num++
		// 					console.log('商品图片',that.canvas_num)//,res.tempFilePath
		// 					if(that.canvas_num==4){
		// 						//绘画画布
		// 						that.canvas(that.width,that.height,true)
		// 					}
		// 				}
		// 			}
		// 		})
		// 		//
		// 	}
		// });
		// 新接口
    app.request(app.apiDomain + 'index.php?c=mall&a=get_goods', {
      goods_id: options.goods_id
    }, function (res) {
      if (res.data.status == '1') {
        var submiturl = '../Order/submit';
        var goods = res.data.data;
        var sku_price_num = goods.sku_price_list[0].total_price + '';
        that.this_time = Math.round(new Date() / 1000);
        var min_pr = goods.f_sku_list[that.data.sku];
        if (min_pr[5]) {
          var min_price = min_pr[5]
        } else if (goods.f_min_price) {
          var min_price = goods.f_min_price
        } else {
          var min_price = min_pr[1];
        };
        // console.log(goods.f_sku_list[that.data.sku][4],123);
        that.setData({
          goods: goods,
          type: options.type,
          goods_id: options.goods_id,
          width: (100 / goods.f_need_assist_num) * goods.has_assist_num + '%',
          user_id: wx.getStorageSync('user_id'),
          isGifts: goods.f_is_gifts == 2 ? 'ok' : 'no',
          url: 'Help?goods_id=' + options.goods_id + '&user_id=' + wx.getStorageSync('user_id'),
          sku_price_num: sku_price_num.split("."),
          banner: goods.f_carousel_img_arr,
          min_price: min_price,
          this_time: that.this_time,
          sheng_num: (goods.first_sku[3] - goods.first_sku[1]).toFixed(1)
        });

        //抢购倒计时
        if (options.type == 'time' && goods.f_end_time > that.this_time) {
          that.time_num = 0;
          that.dynamic_time = 1;
          if (parseFloat(goods.f_begin_time) > that.this_time) { //即将开始
            that.time_type = 1;
          } else if (parseFloat(goods.f_begin_time) < that.this_time) {//进行中
            that.time_type = 2;
            that.setData({
              time_type: 2,
            })
          };
          that.time_function(that, goods)//先执行一次 在循环
          setInterval(function () {
            that.time_function(that, goods)
          }, 1000)
        } else {//已经结束
          that.time_type = 3;
          that.setData({
            time_type: 3
          })
        }

        //
        wx.setNavigationBarTitle({
          title: res.data.data.f_name,
        })
        var WxParse = require('../../wxParse/wxParse.js');
        wx.setStorageSync('title', res.data.data.f_name);
        var article = res.data.data.f_detail_context;
        WxParse.wxParse('article', 'html', article, that, 0);


        //请求商品图片
        wx.downloadFile({
          url: 'https://resource.160nurse.com/' + goods.f_carousel_img_arr[0], //
          success(res) {
            if (res.statusCode === 200) {
              that.canvas_mall = res.tempFilePath;
              that.canvas_num++
              console.log('商品图片', that.canvas_num)//,res.tempFilePath
              if (that.canvas_num == 4) {
                //绘画画布
                that.canvas(that.width, that.height, true)
              }
            }
          }
        })
        //
      }
    })
		app.request(app.apiDomain + 'index.php?c=mall&a=orderUser', {
			goods_id: options.goods_id,
			size: 5
		}, function(res) {
			// console.log(res.data)
			that.setData({
				orderUser: res.data
			})
		})
		//
		// 判断手机号
		app.request(app.apiDomain + 'index.php?c=user&a=checkMobileBind', {}, res => {
			that.setData({
				phone_true:res.data.status
			})
		})
		//判断有没有资格助力
		app.request(app.apiDomain + 'index.php?c=user&a=pointstat', {}, res => {
			that.setData({
				earn_point:res.data.data.earn_point
			})
			// console.log(res)
		})
		//获取屏幕 宽高
		wx.getSystemInfo({
			success(res) {
				that.width = res.screenWidth * 1.6;
				that.height = res.screenWidth * 2.6;
				that.setData({
					c_width:res.screenWidth * 0.8,
					c_height:res.screenWidth * 1.3
				})
			}
		});
		//请求资源
		if(this.o_type=='exchange' || this.o_type=='time'){
			var img_url_1 = 'bg_7.png'
			var img_url_2 = 'bg_9.png'
		}else if(this.o_type=='assist'){
			var img_url_1 = 'bg_6.png'
			var img_url_2 = 'bg_8.png'
		};
		//请求背景图片
		wx.downloadFile({
			url: 'https://resource.160nurse.com/canvas/healthy/img/common/' + img_url_1, 
			success(res) {
				if (res.statusCode === 200) {
					that.canvas_bg = res.tempFilePath;
					that.canvas_num++
					console.log('背景图片',that.canvas_num)//,res.tempFilePath
					if(that.canvas_num==4){
						//绘画画布
						that.canvas(that.width,that.height,true)
					}
				}
			}
		});
		//请求商品覆盖图片
		wx.downloadFile({
			url: 'https://resource.160nurse.com/canvas/healthy/img/common/' + img_url_2, 
			success(res) {
				if (res.statusCode === 200) {
					that.canvas_cover = res.tempFilePath;
					that.canvas_num++
					console.log('商品覆盖图片',that.canvas_num)//,res.tempFilePath
					if(that.canvas_num==4){
						//绘画画布
						that.canvas(that.width,that.height,true)
					}
				}
			}
		});
		
		
		
		//获取二维码
		if(options.type == 'exchange'){
			var op_type = '1'
		}else if(options.type == 'assist'){
			var op_type = '2'
		}else if(options.type == 'time'){
			var op_type = '3'
		};
		this.params = {
			goods_id : options.goods_id,
			type : op_type,
			openid: wx.getStorageSync('openid'),
			f_channel: 'xiaochengxu',
		};
		// console.log(options.type,'当前')
		this.params.sign = app.sign(this.params);
		
	},
  authSuccess(e) {
    this.setData({
      isShow: false
    })
  },
  authFail(e) {
    this.setData({
      isShow: false
    })
  },
  click () {
    this.setData({
      isShow: false
    })
  },
  // getUserInfo: function () {
  //   var that = this
  //   if (app.getUserInfo(that, this.options)) {
  //     that.setData({
  //       user_auth: false
  //     })
  //   }
  // },
	//
	time_function:function(e,goods){
		var that=e;
		that.time_num++
		if(that.time_type == 1 && that.dynamic_time >= 1){//开始倒计时
			that.dynamic_time = goods.f_begin_time - that.this_time - that.time_num;
			
		}else if(that.time_type != 3){  //结束倒计时
			// console.log(that.dynamic_time,that.time_type,time_num)
			if(that.time_type == 1){
				that.time_type = 2;
				that.time_num = 0;
				that.setData({
					time_type:2
				})	
			};
			that.dynamic_time = goods.f_end_time - that.this_time - that.time_num;
			if(that.dynamic_time == -1){
				that.time_type = 3;
				that.setData({
					time_type:3
				})
			}
		}
		let t = parseInt(that.dynamic_time / 86400);//天
		let a = parseInt((that.dynamic_time - (t*86400))/3600);//时
		let b = parseInt((that.dynamic_time - ((a*3600)+(t*86400)))/60);//分
		let c = that.dynamic_time - ((a*3600)+(b*60)+(t*86400));//秒
		// console.log(a+':'+b+':'+c)
		that.setData({
			dynamic_time:t+'天 '+a+':'+b+':'+c
		})
	},
	step_click() {
		wx.chooseAddress({
			success: (res) => {
				this.setData({
					stpe: res.provinceName + '-' + res.cityName + '-' + res.countyName + '-' + res.detailInfo
				});
				app.address = res;
			},
			fail: function(err) {
				// console.log(err)
			}
		})
	},
	num_le:function(){
		if(this.data.mid_num > 1){
			var a = this.data.mid_num - 1;
			this.setData({
				mid_num:a,
				min_price:(this.data.goods.f_min_price * a).toFixed(1)
			})
		}
	},
	num_ri:function(){
		if(this.data.goods.f_xian_gou != '0'){
			if(this.data.mid_num < this.data.goods.f_left_num && this.data.mid_num < this.data.goods.f_xian_gou){
				var a = parseFloat(this.data.mid_num) + 1;
				this.setData({
					mid_num:a,
					min_price:(this.data.goods.f_min_price * a).toFixed(1)
				})
			}
		}else{
			if(this.data.mid_num < this.data.goods.f_left_num){
				var a = parseFloat(this.data.mid_num) + 1;
				this.setData({
					mid_num:a,
					min_price:(this.data.goods.f_min_price * a).toFixed(1)
				})
			}
		}
		
	},
	class_click: function() {
		this.class_suo = false;
		this.setData({
			class_on: 'on',
			class_on2: 'on',
		})
	},
	class_off: function() {
		var thas = this;
		this.setData({
			class_on2: '',
		})
		setTimeout(function(e = thas){
			e.setData({
				class_on:'',
			})
		},300);
	},
	li_click: function(e) {
		this.li_wrds = e.target.dataset.name;
		this.sku_get = e.target.dataset.id;
		if(this.data.goods.f_sku_list[this.sku_get][5]){
			var b = this.data.goods.f_sku_list[this.sku_get][5];
		}else{
			var b = this.data.goods.f_sku_list[this.sku_get][1];
		};
		this.setData({
			sku: this.sku_get,
			min_price:b,
			mid_num:1
		})
	},
	class_get:function(){
		//修改分类文字
		if(!this.li_wrds && !this.sku_get){
			console.log('打开sku但没选')
			this.setData({
				class_on: '',
				li_on:this.data.goods.f_sku_list[0][0],
				sku_get:0
			})
		}else{
			this.setData({
				class_on: '',
				li_on:this.li_wrds,
				sku_get:this.sku_get
			})
		};
		//修改按价格
		var sku_num = this.data.sku_get
		var sku_data = this.data.goods.sku_price_list[sku_num];
		if(this.data.goods.f_sku_list.length >=2){ //是否修改banner
			this.setData({
				banner:this.data.goods.f_sku_img_arr.slice(sku_num,sku_num+1),
				sku_price_num:sku_data.total_price.split('.')
			})
		}else{
			this.setData({
				sku_price_num:sku_data.total_price.split('.')
			})
		}
		//是否弹出原价币抵
		if(this.class_suo){
			var a = {};
			a.currentTarget = {};
			a.currentTarget.dataset = {};
			a.currentTarget.dataset.type = 0;
			a.currentTarget.dataset.fen = this.fen;
			a.currentTarget.dataset.type = this.an_type;
			if(this.data.CartClick){
				this.CartGet();
			}else{
				this.qian_xuan_ze_click(a);
			}
		}
	},
	mall_get: function(e) {
		// this.original = e.currentTarget.dataset.num;
		wx.navigateTo({
			url: '../Order/submit?goods_id=' + this.data.goods.id + '&sku=' + this.data.sku_get + '&type=exchange&original=0&num=' + this.data.mid_num
		})
	},
	qian_xuan_ze_click:function(e){
		var data = e.currentTarget.dataset;
		this.original = data.num;
		this.fen = data.fen;
		this.an_type = data.type;
    let flag = app.isAuth
    if (!flag) {
      this.setData({
        isShow: true
      })
    } else {
      if (this.data.li_on == "请选择分类") {
        console.log('跳出分类')
        this.class_suo = true;
        this.setData({
          class_on: 'on',
          class_on2: 'on',
        })
        return false
      };
      if (this.data.phone_true == 0) {// // 判断手机号 未绑定手机  
        this.setData({
          getPhoneBox: false,
          this_type: data.type,
        })
      } else if (this.fen == '1') {
        //是否直接跳
        wx.navigateTo({
          url: '../Order/submit?goods_id=' + this.data.goods.id + '&sku=' + this.data.sku_get + '&type=exchange&original=' + this.original + '&num=' + this.data.mid_num
        })
      } else if (this.an_type == '3') {
        //抢购
        wx.navigateTo({
          url: '../Order/submit?goods_id=' + this.data.goods.id + '&sku=' + this.data.sku_get + '&type=exchange&original=1&num=' + this.data.mid_num
        })
      } else if (data.type == '0') {
        this.mall_get()
        // 			this.setData({
        // 				this_type:data.type,
        // 			})
      } else {
        // 能送礼 
        wx.navigateTo({
          url: '../activity/writeBless?goods_id=' + this.data.goods.id
        })
      };
    }
	},
// 	qian_xuan_ze_off:function(){
// 		this.setData({
// 			qian_xuan_ze_on:''
// 		})
// 	},
	onReady: function() {
		app.SystemInfo(this)
	},
	onShareAppMessage: function() {
		this.setData({
			g_share_Kill:'off'
		})
		console.log(this.data);
		//app.resourceDomain + '/upload/miniprogram/assist.png'
		if(this.data.earn_point=='0.0' || this.data.earn_point==0){
			var wrds = '健康160';
			var path = "/pages/index/index";
			var img = 'https://resource.160nurse.com/upload/miniprogram/runstep.png';
		}else if(this.data.type == 'assist') {
			var wrds = '帮我助力免费拿' + this.data.goods.f_name +  '，你要不要一起参加？'
			var img = ''
			var path = "/pages/mall/Help?user_id=" + this.data.user_id + '&goods_id=' + this.data.goods.id;
		} else {
			var wrds = '仅需 ¥' + this.data.goods.f_min_price + ' 抢购' + this.data.goods.f_name
			var img = ''
			var path = "/pages/mall/detail?type=" + this.data.type + '&goods_id=' + this.data.goods.id;
			//服务
			if(this.data.goods.f_is_form==4){
				wrds = this.data.goods.f_name + ',预约价仅需 ¥' + (this.data.goods.f_min_price ? this.data.goods.f_min_price : 0);
			}
			//抢购
			if(this.data.goods.f_type == '105103104'){
				wrds = '仅需 ¥' + this.data.goods.f_min_price + ' 限时抢购' + this.data.goods.f_name
			}
		}
		// console.log(wrds)
		return {
			path: path,
			title: wrds,
			imageUrl: img
		}
	},
	sendOrSelf_click:function() {
		this.setData({
			selectBox: true
		})
	},
	getPhoneBox_click:function() {
		this.setData({
			getPhoneBox: true
		})
	},
	goods_click: function(options) {
		var thas = this;
		if(thas.data.earn_point=='0.0' || thas.data.earn_point==0){
			wx.showToast({
				title:'领取过健康币的用户才有权限发起助力,请先去首页领取健康币',
				icon: 'none',
				duration: 2000
			})
			return false
		}
		app.request(app.apiDomain + 'index.php?c=mall&a=jointassist', {
			goods_id: thas.data.goods_id,
		}, function(res) {
			console.log(res.data.info)
		})
	},
	// 获取手机号信息  绑定
	getPhoneNumber(e) {
		var thas=this;
		console.log(e)
		app.request(app.apiDomain + 'index.php?c=user&a=userbinding', {
			encryptedData: e.detail.encryptedData,
			iv: e.detail.iv
		}, res => {
			// console.log(res)
			if(res.data.status == 0){
				wx.showToast({
					title: res.data.info,
					icon: 'none',
					duration: 2000
				});
				thas.setData({
					getPhoneBox: true
				});
				return false
			}else{// 绑定成功
				// 判断是否为送礼
				// console.log(thas.data.this_type)
				if(thas.data.this_type == 0 || thas.data.this_type == '0' || thas.data.type == 'assist') {// 不能送礼
					thas.mall_get()
// 					thas.setData({
// 						qian_xuan_ze_on:'on',
// 						getPhoneBox: true
// 					})
				} else {
					wx.navigateTo({
						url: '../activity/writeBless?goods_id=' + thas.data.goods.id
					})
				}
			}
			

		})
	},
	jumpOver(e) {
		// console.log(this.ren_suo)
		// 未绑定手机  
		this.setData({
			getPhoneBox: true
		})
	},
	g_share_click:function(){
		this.setData({
			g_share_on:'on',
			g_share_Kill:''
		})
	},
	g_share_off:function(){
		this.setData({
			g_share_on:'',
			g_share_index_on:''
		})
	},
	g_share_index_click:function(){
		var that = this;
		if(!this.canvas_suo){
			app.request(app.apiDomain + 'index.php?c=mall&a=goodsQrcode', that.params, res => {
				wx.downloadFile({
					url: res.data.data.file_path, 
					success(res) {
						// console.log(res,'2')
						if (res.statusCode === 200) {
							that.canvas_pcode = res.tempFilePath;
							that.canvas_num++
							console.log('获取二维码',that.canvas_num)//,res.tempFilePath
							if(that.canvas_num==4){
								//绘画画布
								that.canvas(that.width,that.height,true)
							}
						}
					},
				});
				if(res.data.status !=1){
					wx.showToast({
						title: '生成二维码失败请联系客服',
						icon: 'none',
						duration: 1000
					})
				}
			})
		}
		this.setData({
			g_share_on:'',
			g_share_index_on:'on'
		})
	},
	canvas:function(a,b,c){
		//基础配置
		var width = a;
		var height = b;
		var new_open = c;
		var vw = width / 100 ;
		var q_win = width*0.06; 
		var c_sku = this.data.sku;
		// console.log(this.data.goods.f_sku_list[c_sku][4])
		var context = wx.createCanvasContext('canvas')
		//基础设置
		context.width = width;
		context.height = height;
		context.setFillStyle('#FFFFFF');
		context.fillRect(0, 0, width, height);
		
		//开始插入背景
		context.drawImage(this.canvas_bg, 0, 0, width, width*1.16);
		//插入商品
		context.drawImage(this.canvas_mall, 15*vw, 6*vw, 70*vw, 70*vw);
		//插入覆盖图
		context.drawImage(this.canvas_cover, 15*vw, 6*vw, 70*vw, 70*vw);
		//价格或助力
		if(this.data.goods.f_is_form == '4'){ //预约
			//活动价
			context.setFontSize(6.4*vw);
			context.setFillStyle('#ff4c33');
			let first_sku4 = this.data.goods.f_sku_list[c_sku][4];
			context.fillText(first_sku4, q_win , width*0.94);
			//元的距离
			q_win =  q_win + ((first_sku4+'').length * 4 * vw);
			context.setFontSize(4*vw);
			context.fillText('元', q_win , width*0.94);
			//插入市场价
			context.setFontSize(4*vw);
			q_win = q_win + (6*vw);
			let first_sku3 = this.data.goods.f_sku_list[c_sku][3];
			context.fillText('市场价：¥' + first_sku3 , q_win , width*0.94);
			//预约价
			context.setFontSize(4*vw);
			q_win = width*0.06;
			context.fillText('预约金：¥', q_win , width*1);
			//预约价多少钱
			q_win = q_win + (19 * vw);
			let f_min_price = this.data.goods.f_min_price;
			context.fillText(f_min_price, q_win , width*1);
			//到院再付
			q_win = q_win + ((f_min_price+'').length * 3 * vw);
			context.fillText('到院再付 ¥', q_win , width*1);
			//再付多少钱
			q_win = q_win + (20 * vw);
			let f_price = this.data.goods.f_sku_list[c_sku][4] - this.data.goods.f_min_price;
			context.fillText(f_price, q_win , width*1);
			
		}else if(this.o_type == 'exchange' || this.o_type == 'time'){//健康币 和限时抢购
			//多少币
			let f_point_num = this.data.goods.f_sku_list[c_sku][2];
			if(f_point_num && f_point_num != '0'){//判断是否有值
				context.setFontSize(6.4*vw);
				context.setFillStyle('#ff4c33');
				context.fillText(f_point_num, width*0.06 , width*0.94);
				//币的距离
				q_win = q_win + (f_point_num+'').length * 4 * vw;
				context.setFontSize(4*vw);
			}
			//多少钱
			let f_min_price = this.data.goods.f_min_price;
			// console.log(f_min_price,'判断是否有值')
			if(f_min_price){//判断是否有值
				if(f_point_num && f_point_num != '0'){
					context.fillText('健康币 +', q_win , width*0.94);
					q_win = q_win + (17*vw);
				}
				context.setFontSize(6.4*vw);
				// console.log(q_win,123)
				context.fillText(f_min_price, q_win , width*0.94);
				//元的距离
				q_win = q_win + ((f_min_price+'').length * 4 * vw);
				context.setFontSize(4*vw);
				context.fillText('元', q_win , width*0.94);
			}else{
				context.fillText('健康币', q_win , width*0.94);
			};
			//插入市场价
			context.setFontSize(3.2*vw);
			q_win = q_win + (6*vw);
			let c_name = this.data.goods.f_sku_list[c_sku][4] ? this.data.goods.f_sku_list[c_sku][4]:'市场';
			context.fillText(c_name + '价：¥' + this.data.goods.f_sku_list[c_sku][3] , q_win , width*0.94);
			//插入商品名称
			context.setFontSize(5*vw);
			context.setFillStyle('#611c21');
		}else if(this.o_type == 'assist'){//助力
			context.setFontSize(6.4*vw);
			context.setFillStyle('#ffffff');
			let f_need_assist_num = this.data.goods.f_need_assist_num;
			context.fillText(f_need_assist_num, (6*vw) , width*0.94);
			context.setFontSize(4*vw);
			context.fillText('人助力免费拿', ((f_need_assist_num+'').length * 4 * vw) + (6*vw) , width*0.935);
			//插入商品名称context.measureText(f_need_assist_num).width 
			context.setFontSize(5*vw);
		}
		//商品名称
		context.fillText(this.data.goods.f_alias_name, width * 0.06, width *0.85);
		//插入二维码
		context.drawImage(this.canvas_pcode, 32*vw, 118*vw, 33*vw, 33*vw);
		//插入二维码文字
		context.setFontSize(4.2*vw)
		context.setFillStyle('#999999')
		context.fillText('长按识别小程序码立即省钱购', width*0.23 , width*1.57);
		
		//渲染页面
		var thas=this;
		context.draw(setTimeout(function(e=thas) {
			e.canvas_suo=true;
			e.getTempFilePath(false)
		},1000));
		
	},
	canvas_click:function(){
		//保存画布
		if(this.canvas_suo){
			this.getTempFilePath(true)
		}else{
			wx.showToast({
				title: '正在绘画中，请稍后在试',
				icon: 'none',
				duration: 1000
			})
		}
	},
	getTempFilePath: function(e) {
		var THIS=this;
		wx.canvasToTempFilePath({
			canvasId: 'canvas',
			fileType:'jpg',
			quality:1,
			success: (res) => {
				console.log('绘画图片')
				THIS.setData({
					canvas_text:'off'
				})
				if(e){//保存至相册
					wx.hideLoading()
					wx.saveImageToPhotosAlbum({
						filePath:  res.tempFilePath,
						success: (res) => {
							wx.showToast({
								title: '保存成功',
								icon: 'none',
								duration: 1000
							})
						},
						fail: (err) => {
							// console.log(err)
						}
					});
				}else{
					THIS.setData({
						canvas_image:res.tempFilePath
					})
					// console.log(THIS.data.canvas_image,1,THIS)
				}
			}
		})
	},
  return_act() {
    let pages = getCurrentPages()
    if (pages.length == 1) {
      wx.reLaunch({
        url: '../mall/index',
      })
    } else {
      wx.navigateBack({
        
      })
    }
  },
  return_index() {
    wx.reLaunch({
      url: '../index/index',
    })
  },
  onShow: function() {
    // (trigger.trigger)(this, '../mall/detail', this.options.goods_id, this.options.type)
  }
})